﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SoldierStateManager
{

    private StateSystem m_StateSystem;      //创建一个主角状态跃迁的管理员
    public StateSystem StateSystem
    {
        get
        {
            return m_StateSystem;
        }
    }

    public GameObject obj;

    public SoldierStateManager(GameObject obj)
    {
        this.obj = obj;
    }

    public void InitStateSystem()         //初始化管理员
    {
        IdleState idle = new IdleState(this);
        idle.AddTransition(Transition.eTransiton_Object_Run, StateID.eStateID_Object_Run);
        idle.AddTransition(Transition.eTransiton_Object_Attack, StateID.eStateID_Object_Attack);
        idle.AddTransition(Transition.eTransiton_Object_Dead, StateID.eStateID_Object_Dead);

        RunState run = new RunState(this);
        run.AddTransition(Transition.eTransiton_Object_Idle, StateID.eStateID_Object_Idle);
        run.AddTransition(Transition.eTransiton_Object_Attack, StateID.eStateID_Object_Attack);
        run.AddTransition(Transition.eTransiton_Object_Dead, StateID.eStateID_Object_Dead);


        AttackState attack = new AttackState(this);
        attack.AddTransition(Transition.eTransiton_Object_Run, StateID.eStateID_Object_Run);
        attack.AddTransition(Transition.eTransiton_Object_Idle, StateID.eStateID_Object_Idle);
        attack.AddTransition(Transition.eTransiton_Object_Dead, StateID.eStateID_Object_Dead);



        //HurtState hurt = new HurtState(this.gameObject, this);
        //hurt.AddTransition(Transition.eTransiton_Object_Idle, StateID.eStateID_Object_Idle);
        //hurt.AddTransition(Transition.eTransiton_Object_Dead, StateID.eStateID_Object_Dead);
        //hurt.AddTransition(Transition.eTransiton_Object_Rush, StateID.eStateID_Object_Rush);

        DeadState dead = new DeadState(this);
        dead.AddTransition(Transition.eTransiton_Object_Idle, StateID.eStateID_Object_Idle);

        m_StateSystem = new StateSystem();
        m_StateSystem.AddState(idle);
        m_StateSystem.AddState(run);
        m_StateSystem.AddState(attack);
        m_StateSystem.AddState(dead);
        //m_StateSystem.AddState(hurt);
    }
    public void SetTransition(Transition t)            //跃迁到指定状态
    {
        m_StateSystem.PerformTransition(t);
    }

    public StateID GetCurrentStateID()
    {
        return m_StateSystem.CurrentStateID;
    }

    public StateID GetLastStateID()
    {
        return m_StateSystem.LastStateID;
    }

    public State GetState(StateID id)
    {
        return m_StateSystem.GetState(id);
    }
    public void Init()
    {
    }
}
